package org.dru.clay.util.file;

import org.dru.clay.util.functional.CollectionUtils;
import org.dru.clay.util.functional.Predicates;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * DefaultFileSet
 * User: joakimd
 * Date: 2013-07-24
 * Time: 15:20
 */
public class DefaultFileSet extends AbstractFileSet {
    private Collection<File> files;

    public DefaultFileSet(final File dir, final Iterable<File> files) {
        super(dir);
        if (!CollectionUtils.every(files, FilePredicates.isRelativeOf(dir))) {
            throw new IllegalArgumentException("one or more list is not relative of " + dir);
        }
        this.files = new ArrayList<File>(CollectionUtils.filter(files, Predicates.<File>alwaysTrue()));
    }

    public DefaultFileSet(final FileSet other) {
        this(other.getDir(), other);
    }

    @Override
    public Iterator<File> iterator() {
        return files.iterator();
    }
}
